package com.example;

import com.example.factory.MybatisImportBeanDefinitionRegister;
import com.example.inter.YinScan;
import com.example.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName YinApplication
 * @Description
 * @Author Yin
 * @Date 2021/4/8 15:19
 * @Version 1.0
 */
@ComponentScan("com.example")
@YinScan("com.example.mapper")
public class YinApplication {

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        return new SqlSessionFactoryBuilder().build(resourceAsStream);
    }


    public static void main(String[] args) {

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(YinApplication.class);

        applicationContext.refresh();

        UserService userService = applicationContext.getBean("userService", UserService.class);
        userService.test();
    }
}
